import http from "@/api";
import { ResPage, OrgManager } from "@/api/interface/index";
import qs from "qs";
/**
 * @name 事件管理模块
 */

// 分页查询通知事件列表
export const findPageRequests = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  return http.post(`/pages/request!findRequests.action?1=1`, qs.stringify(newobj));
};

// 保存请求
export const saveRequest = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  return http.post("" + `/pages/request!saveRequest.action` + idsStr, qs.stringify(newobj));
};
